package com.reggie.controller.admin;

import com.reggie.result.R;
import com.reggie.service.ShopService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController("adminShopRestController")
@RequestMapping("/admin/shop")
@Api(tags = "商店操作相关接口")
public class ShopController {

    @Autowired
    private ShopService shopService;

    /**
     * 设置商店状态
     */
    @PutMapping("/{status}")
    @ApiOperation("设置营业状态的接口")
    public R<String> shopStatus(@PathVariable Integer status){
        log.info("设置营业状态的参数：" + status);
        shopService.update(status);
        return R.success();
    }

    /**
     * 获取商店状态
     */
    @GetMapping("/status")
    @ApiOperation("获取营业状态")
    public R<Integer> findShopStatus(){
        log.info("获取营业状态：");
        Integer shopStatus = null;
        try {
            shopStatus = shopService.findShopStatus();
        } catch (Exception e) {
            e.printStackTrace();
            shopStatus =1;
        }

        return R.success(shopStatus);
    }
}
